{% extends base %}

{% block body_left %}

{% init show_delete = True %}
{% init dict_title = "编辑" %}

{% include dict/page/dict_edit_base.html %}

<script>
    $(".save-btn").click(function (e) {
        var params = {};
        params.dict_id = xnote.getUrlParam("dict_id");
        params.key = $("[name=name]").val();
        params.value = $("[name=value]").val();
        params.dict_type = "{{dict_type}}";
        xnote.http.post("/api/dict/update", params, function (resp) {
            if (resp.code == "success") {
                xnote.toast("更新成功");
            } else {
                xnote.toast("更新失败:" + resp.message);
            }
        }).fail(function (err) {
            xnote.toast("请求失败:" + err);
        })
    });

    // 删除
    $(".delete-btn").click(function (e) {
        var key = $(".dict-key").val();
        var confirmText = "确认删除[" + key + "]吗?";
        xnote.confirm(confirmText, function (result) {
            var params = {};
            params.dict_id = xnote.getUrlParam("dict_id");
            params.dict_type = "{{dict_type}}";
            xnote.http.post("/api/dict/delete", params, function (resp) {
                if (resp.success) {
                    xnote.toast("删除成功");
                    window.location.href = "/dict/list?dict_type={{dict_type}}";
                } else {
                    xnote.toast("删除失败:" + resp.message);
                }
            });
        });
    });
</script>

{% end %}

{% block body_right %}
    {% include dict/page/dict_sidebar.html %}
{% end %}
